import React, { Component } from "react";
import { Link, Route, Switch, Redirect } from "react-router-dom";

class Home extends Component {
  render() {
    return <div>这是首页页面</div>;
  }
}

const About = () => {
  return <div>这是关于页面</div>;
};

const NotFound = () => {
  return <div>404 not found...</div>;
};

class App extends Component {
  render() {
    return (
      <>
        <h2>404路由</h2>
        <ul>
          <li>
            <Link to="/home">首页</Link>
          </li>
          <li>
            <Link to="/about">关于页</Link>
          </li>
        </ul>

        <hr />

        <Switch>
          {/* 404页面必须和Switch一起用，并且必须放在所有的Route的最下面 */}
          <Redirect from="/" to="/home" exact></Redirect>
          <Route path="/home" component={Home}></Route>
          <Route path="/about" component={About}></Route>
          <Route path="*" component={NotFound}></Route>
        </Switch>
      </>
    );
  }
}

export default App;
